﻿Public Class PrintView

    Private mVM As HeapViewModel

    Public Sub New(ByVal vm As HeapViewModel)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        mVM = vm
        Me.DataContext = mVM
    End Sub

    Private Sub PrintView_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        'load rows of results in table
        Dim isAlternatingRow As Boolean = False
        For Each i As ResultsItem In mVM.Results
            Dim row As New TableRow
            If isAlternatingRow Then
                row.Background = Brushes.AliceBlue
            End If
            isAlternatingRow = Not isAlternatingRow

            row.Cells.Add(CreateCell(i.ClassName))
            row.Cells.Add(CreateCell(i.CountString))
            row.Cells.Add(CreateCell(i.CountChangePercent.ToString))
            row.Cells.Add(CreateCell(i.SizeString))
            row.Cells.Add(CreateCell(i.SizeChangePercent.ToString))
            row.Cells.Add(CreateCell(i.MT))
            Me.ResultsRows.Rows.Add(row)
        Next
        Me.PrintDocument.Print()
    End Sub

    Private Function CreateCell(ByVal content As String) As TableCell
        Dim cell As New TableCell(New Paragraph(New Run(content)))
        Return cell
    End Function

    Private Sub btnPrint_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        Me.PrintDocument.Print()
    End Sub

    Private Sub btnClose_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        Me.Close()
    End Sub
End Class
